package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author hu hanSan
 * @Date 2024-09-09
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;
    @Autowired
    private NursingPlanMapper nursingPlanMapper;
    /**
     * 查询所有护理等级
     *
     * @return
     */
    @Override
    public List<NursingLevelVo> getListAll() {
        List<NursingLevelVo> list= nursingLevelMapper.selectListAll();
        return list;
    }

    /**
     * 新增护理等级
     *
     * @param nursingLevelDto
     */
    @Override
    public void addLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
      //  NursingPlan nursingPlan = new NursingPlan();
       // nursingPlanMapper.insertPlan(nursingPlan);
      //  Long id = nursingPlan.getId();
      //  nursingLevel.setLplanId(id);
        nursingLevelMapper.insertLevel(nursingLevel);
    }


    /**
     * 条件分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> page(String name, Integer status, Integer pageNum, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo>page= nursingLevelMapper.getByPage(name,status);
        //封装对象并返回
         PageResponse<NursingLevelVo> pageResponse=new PageResponse<>(page);
        //PageResponse<NursingLevelVo> pageResponse=PageResponse.of(page, NursingLevelVo.class);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 根据id来查询
     *
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo getById(Long id) {
       NursingLevel nursingLevel= nursingLevelMapper.getById(id);
        NursingLevelVo bean = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
        return bean;
    }

    /**
     * 启用和禁用
     *
     * @param id
     * @param status
     */
    @Override
    public void putStatus(Long id, Integer status) {
        nursingLevelMapper.putStatus(id,status);
    }

    /**
     * 根据id来删除
     *
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        nursingLevelMapper.deleteById(id);
    }

    /**
     * 修改护理等级
     *
     * @param nursingLevelDto
     */
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updateLevel(nursingLevel);
    }
}
